package com.ss.tmall.controller;

import com.ss.tmall.pojo.Product;
import com.ss.tmall.pojo.PropertyValue;
import com.ss.tmall.service.ProductService;
import com.ss.tmall.service.PropertyValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: ShengShuai
 * @Description:
 * @Date: Created in 下午 14:24  2017/12/27 0027
 * @Modified By:
 */
@Controller
@RequestMapping("")
public class PropertyValueController {
    @Autowired
    PropertyValueService propertyValueService;
    @Autowired
    ProductService productService;
    @RequestMapping("admin_propertyValue_edit")
    public  String edit(Model model,int pid){
        Product product=productService.get(pid);
        propertyValueService.init(product);
        List<PropertyValue> propertyValues =propertyValueService.list(product.getId());
        model.addAttribute("p",product);
        model.addAttribute("pvs",propertyValues);
        return  "admin/editPropertyValue";
    }
    @RequestMapping("admin_propertyValue_update")
    @ResponseBody
    public String update(PropertyValue propertyValue){
propertyValueService.update(propertyValue);
return  "success";
    }
}
